package listbyorder.access001_100.test71;

import java.util.Stack;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/3 21:39
 */
public class Solution1 {

    public String simplifyPath(String path) {
        String[] split = path.split("/");
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < split.length; i++) {
            if (split[i].equals("..")) {
                if (!stack.isEmpty()) {
                    stack.pop();
                }
            } else if (split[i].equals("") || split[i].equals(".")) {
                continue;
            } else {
                stack.push(split[i]);
            }
        }
        if (stack.isEmpty()) return "/";
        String ans = "";
        while (!stack.isEmpty()) {
            ans = "/" + stack.pop() + ans;
        }
        return ans;
    }
}
